﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<Shamrock.Helpers.PaginatedList<Shamrock.Models.Message>>" ValidateRequest="false" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
	Shamrock
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
        <hr />
        <% Html.RenderPartial("MessageForm", ViewData["NewMessage"]); %>
        <hr />

    <div class="threads">
    <% foreach (var item in Model) { %>
        <div class="threadStructure" id="thread<%: item.MessageID %>">
            <div class="threadPost" id="r<%: item.MessageID %>">
                <% if(item.HasMap) { %>
                <img alt="<%: item.Map.Address %>" title="<%: item.Map.Address %>"
                    src="http://maps.google.com/maps/api/staticmap?center=<%: item.Map.Latitude %>,<%: item.Map.Longitude %>&zoom=<%: item.Map.Zoom %>&size=300x300&markers=color:red|<%: item.Map.Latitude %>,<%: item.Map.Longitude %>&sensor=false" />
                <% } %>
                <% if(item.HasImage) { %>
                <span class="fileDescription">
                File : 
                <a target="_blank" href="<%: item.Image.ViewFilePath %>"><%: item.Image.FileName %></a>-(<%: item.Image.SizeKB %> KB, <%: item.Image.Width %>x<%: item.Image.Height %>)
                </span>
                <br />
                <a target="_blank" href="<%: item.Image.ViewFilePath %>"><img alt="<%: item.Image.SizeKB %>KB" width="<%: item.Image.ThumbWidth %>" height="<%: item.Image.ThumbHeight %>" src="<%: item.Image.ViewThumbPath %>" /></a>
                <% } %>
                <span class="subject" id="threadSubject<%: item.MessageID %>"><%: item.SubjectDefault %></span>
                Name
                <span class="name">
                <% if (item.Email != null) { %>
                <a href="mailto:<%: item.Email %>"><%: item.PosterDefault %></a>
                <% }else{ %>
                <%: item.PosterDefault %>
                <% } %>
                </span>
                [<%: item.PostDateWithWeekday %>]
                <span class="postID">No.<%: item.MessageID %></span>
                [<%= Html.RouteLink("Reply", "ReplyLastPage", new { id = item.MessageID }) %>]
                <div class="comment">
                    <%= Html.Encode(item.CommentDefault).Replace("\n", "<br />") %>
                </div>
                <% if(item.Omitted > 0) { %>
                <span class="warningText">有回應 <%: item.Omitted %> 篇被省略，要閱讀所有回應請按下回應連結</span>
                <% } %>
            </div>

            <% foreach (var reply in item.IndexReplies) { %>
            <div class="reply" id="r<%: reply.MessageID %>">
                <span class="subject" id="replySubject<%: reply.MessageID %>"><%: reply.SubjectDefault %></span>
                Name
                <span class="name">
                <% if (reply.Email != null) { %>
                <a href="mailto:<%: reply.Email %>"><%: reply.PosterDefault %></a>
                <% }else{ %>
                <%: reply.PosterDefault %>
                <% } %>
                </span>
                [<%: reply.PostDateWithWeekday %>]
                <span class="postID">No.<%: reply.MessageID %></span>
                <div class="comment">
                    <%= Html.Encode(reply.CommentDefault).Replace("\n", "<br />") %>
                </div>
            </div>
            <% } %>
        </div>
        <hr />
    <% } %>
    </div>

    <div class="pagination">
        <table>
        <tr>
            <td>
            <% if (Model.HasPreviousPage) { %>        
                <%: Html.RouteLink("上一頁", 
                                   "IndexThreads", 
                                   new { page=(Model.PageIndex-1) }) %>
            <% }else{ %>
                第一頁
            <% } %>
            </td>
            <td>
            <% for (int i = 0; i < Model.TotalPages; i++){ %>
                <% if (i != Model.PageIndex) { %>
                    [<%: Html.RouteLink(i.ToString(),
                                       "IndexThreads", 
                                       new { page=(i) }) %>]
                <% } else { %>
                    [<%: i %>]
                <% } %>
            <% } %>
            </td>
            <td>
            <% if (Model.HasNextPage) { %>        
                <%: Html.RouteLink("下一頁", 
                                   "IndexThreads", 
                                   new { page=(Model.PageIndex+1) }) %>
            <% }else{ %>
                最後一頁
            <% } %>
            </td>
        </tr>
        </table>
    </div>

</asp:Content>

